import http from '@/axios'
import {handleError} from "vue";
import {handleSuccess} from "@/api/index.js";

export const deptAPI = {
     // 获取部门列表
    list(params) {
        return http.get('/api/dept/list', {params: {...params}})
            .then(res => handleSuccess(res, '获取部门列表成功'))
            .catch(error => handleError(error, '获取部门列表失败', '服务器异常'));
    },

    //获取部门详情
    getDeptById: (id) => {
        return http.get(`/api/dept/detail/${id}`)
        .then(res => handleSuccess(res, '获取部门详情成功'))
        .catch(error => handleError(error, '获取部门详情失败', '服务器异常'));
    },
    
    //删除部门
    deleteDept: (id) => {
        return http.delete(`/api/dept/delete/${id}`)
        .then(res => handleSuccess(res, '删除部门成功'))
        .catch(error => handleError(error, '删除部门失败', '服务器异常'));
    },

    //创建部门
    createDept: (data) => {
        return http.post('/api/dept/create', data)
        .then(res => handleSuccess(res, '创建部门成功'))
        .catch(error => handleError(error, '创建部门失败', '服务器异常'));
    },

    //获取部门树
    getDeptTree: () => {
        return http.get('/api/dept/tree')
        .then(res => handleSuccess(res, '获取部门树成功'))
        .catch(error => handleError(error, '获取部门树失败', '服务器异常'));
    },

    //更新部门
    updateDept: (data) => { 
        return http.put('/api/dept/update', data)
        .then(res => handleSuccess(res, '更新部门成功'))
        .catch(error => handleError(error, '更新部门失败', '服务器异常'));

    },  


}

export default deptAPI;
